#include <QApplication>
#include <QDebug>

#include "InputEngineDBusClient.h"



int main(int argc, char** argv) {


    QApplication app(argc, argv);

    InputEngineDBusClient ie(COM_CPIS_ENGINE_NAME, COM_CPIS_ENGINE_OBJECT_PATH, QDBusConnection::sessionBus());

    //qRegisterMetaType<QStringMap>(); //only for qt property system
    qDBusRegisterMetaType<QStringMap>();
    qDBusRegisterMetaType<QIntList>();
    qDBusRegisterMetaType<Int2>();
    qDBusRegisterMetaType<QInt2List>();




    QStringList keys;
    keys << "key1" << "key2";

    QDBusPendingReply<QStringMap> reply = ie.AcquireInformation("lee", keys);
    reply.waitForFinished();
    qDebug() << reply.isError() << reply.argumentAt(0) << reply.value();

    QIntList il;
    il.append(6); il.append(8);
    
    QDBusPendingReply<QIntList> reply2 = ie.PushChars("lee", il);
    reply2.waitForFinished();
    qDebug() << reply2.isError() << reply2.argumentAt(0) << reply2.value();

    QInt2List i2l;
    i2l.append({6, 8}); i2l.append({9, 10});
    
    QDBusPendingReply<QIntList> reply3 = ie.PushCoordinates("lee", i2l);
    reply3.waitForFinished();
    qDebug() << reply3.isError() << reply3.argumentAt(0) << reply3.value();

    QStringList pinyins; 
    QString composition, commit, hint;
    int status = 0;

    QDBusReply<QStringList> reply4 = ie.AcquireResult("lee", pinyins, composition, commit, hint, status);
    qDebug() << reply4.isValid() << reply4.error()  << reply4.value() << pinyins << composition << commit << hint << status;

    QDBusPendingReply<QStringList, QStringList, QString, QString, QString, int> reply5 = ie.AcquireResult("lee");
    reply5.waitForFinished();
    qDebug() << reply5.isError() << reply5.argumentAt(0) << reply5.argumentAt(1) << reply5.argumentAt(2) << reply5.argumentAt(3)<< reply5.argumentAt(4)<< reply5.argumentAt(5) << reply5.value() ;

    QObject::connect(&ie, &InputEngineDBusClient::Event, 
                     [](const QString &uid, int single, const QByteArray &data, uint size) {
        qDebug() << uid << single << data << size;
    });

    return app.exec();

}
